package com.ruoyi.common.domin;

import struct.StructClass;
import struct.StructField;

/**
 * @ClassName UpInformationPackage
 * @Description 信息上传帧
 * @Author 张勇
 * @Date 2024-09-29
 * @Version 1.0.0
 */
@StructClass
public class UpInformationPackage {
    //分站IP
    @StructField(order = 0)
    public byte[] stationIp = new byte[4];
    //日期
    @StructField(order = 1)
    public byte[] dataDate = new byte[4];
    //时间
    @StructField(order = 2)
    public byte[] dataTime = new byte[4];
    //控制器状态
    @StructField(order = 3)
    public byte[] controlState = new byte[1];
    //设备状态
    @StructField(order = 4)
    public byte[] deviceState = new byte[1];
    //报警原因
    @StructField(order = 5)
    public byte[] alarmReason = new byte[1];
    //检修模式
    @StructField(order = 6)
    public byte[] overhaulModel = new byte[1];
    //输入1 – 输入8
    @StructField(order = 7)
    public byte[] inputOneToEight = new byte[8];
    //保留
    @StructField(order = 8)
    public byte[] obtainField = new byte[128];


    /**
     * 获取分站IP地址
     * @return
     */
    public String getStationIp() {
        return
        (stationIp[0] & 0XFF) +"."+
        (stationIp[1] & 0XFF)+"."+
        (stationIp[2] & 0XFF)+"."+
        (stationIp[3] & 0XFF);

    }

    /**
     * 获取分站时钟
     * @return
     */
    public String getStationClock(){
        //======================分站时钟计算================================
        String stationYear = "20" + TypeConvertUtils.byteToHexString(dataDate[0]);  //年
        String stationMonth = TypeConvertUtils.byteToHexString(dataDate[1]);        //月
        String stationDay = TypeConvertUtils.byteToHexString(dataDate[2]);          //日

        String stationHour = TypeConvertUtils.byteToHexString(dataTime[0]);         //时
        String stationMinute = TypeConvertUtils.byteToHexString(dataTime[1]);       //分
        String stationSecond = TypeConvertUtils.byteToHexString(dataTime[2]);       //秒

        //分站时钟
        String stationClock = stationYear + "-" + stationMonth + "-" + stationDay + " "
                + stationHour + ":" + stationMinute + ":" + stationSecond;
        return stationClock;
    }

    /**
     * 获取控制器状态
     * @return
     */
    public String getControlState() {
        return
                String.valueOf(controlState[0] & 0XFF);
//        return TypeConvertUtils.byteToBin(controlState[0]);
    }

    /**
     * 获取设备状态
     * @return
     */
    public String getDeviceState() {
        return
                String.valueOf(deviceState[0] & 0XFF);
//        return TypeConvertUtils.byteToBin(deviceState[0]);
    }

    /**
     * 获取报警原因
     * @return
     */
    public String getAlarmReason() {
        return
                String.valueOf(alarmReason[0] & 0XFF);
//        return TypeConvertUtils.byteToBin(alarmReason[0]);
    }

    /**
     * 获取检修模式
     * @return
     */
    public String getOverhaulModel() {
        return
                String.valueOf(overhaulModel[0] & 0XFF);
    }

    /**
     * 获取输入1的状态
     * @return
     */
    public String getInputOne(){
        return String.valueOf(inputOneToEight[0] & 0XFF);

    }
    /**
     * 获取输入2的状态
     * @return
     */
    public String getInputTwo(){
        return
                String.valueOf(inputOneToEight[1] & 0XFF);


    }
    /**
     * 获取输入3的状态
     * @return
     */
    public String getInputThree(){

        return
                String.valueOf(inputOneToEight[2] & 0XFF);

    }
    /**
     * 获取输入4的状态
     * @return
     */
    public String getInputFour(){
        return
                String.valueOf(inputOneToEight[3] & 0XFF);
    }
    /**
     * 获取输入5的状态
     * @return
     */
    public String getInputFive(){
        return String.valueOf(inputOneToEight[4] & 0XFF);
    }
    /**
     * 获取输入6的状态
     * @return
     */
    public String getInputSix(){
        return String.valueOf(inputOneToEight[5] & 0XFF);
    }
    /**
     * 获取输入7的状态
     * @return
     */
    public String getInputSeven(){
        return String.valueOf(inputOneToEight[6] & 0XFF);
    }
    /**
     * 获取输入8的状态
     * @return
     */
    public String getInputEight(){
        return String.valueOf(inputOneToEight[7] & 0XFF);
    }
}
